package com.shujia.flink.tf

import org.apache.flink.api.common.functions.FilterFunction
import org.apache.flink.streaming.api.scala._

object Demo4Filter {
  def main(args: Array[String]): Unit = {
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment
    val studentDS: DataStream[String] = env.readTextFile("data/students.txt")

    val filterDS: DataStream[String] = studentDS.filter(new FilterFunction[String] {
      /**
       * filter: 每一条数据执行一次，如果返回true保留数据，如果返回false过滤数据
       *
       * @param value ： 一行数据
       * @return
       */
      override def filter(value: String): Boolean = {
        val clazz: String = value.split(",").last
        //取出文科的学生
        clazz.startsWith("文科")
      }
    })

    filterDS.print()
    env.execute()
  }

}
